﻿/******************************************************************************
* File description: CustomRadio.qml
* Function: 单选按钮
* Current Version: 1.0.0
 *****************************************************************************/
import QtQuick 2.0

Rectangle {
    property string title: "单选框"
    height: 40*dp
    id: root
    width: Math.max(50*dp, item_circle.width + item_text.width + 12*dp)



    property color background_color: "transparent"
    property color background_color_select: "transparent"
    property color background_border: "transparent"
    property color background_border_select: "transparent"

    property color font_color: "#333333"
    property color box_color: config.themeColor

    radius: 3*dp

    property real box_size: 16*dp

    property bool checked: false
    property bool editable: true

    color: checked ? background_color_select : background_color
    border.color: checked ? background_border_select : background_border

    signal clicked()

    // 小圆圈
    Item{
        id: item_circle
        height: root.height; width: box_size*2
        Rectangle{
            anchors.centerIn: parent
            radius: box_size * 0.5
            height: box_size; width: box_size
            color: editable ? "white" : "#F4F4F4"
            border.color: checked ? (editable?box_color:"#CCC") : "#CCC"
            border.width: checked ? box_size * 0.3 : 1
        }

    }

    // 文字
    Item{
        id: item_text
        height: root.height; width: text.contentWidth
        x: box_size * 2.1
        Text {
            id: text
            font.pixelSize: config.fontsize
            anchors.verticalCenter: parent.verticalCenter
            text: title
        }
    }
    MouseArea{
        height: Math.max(text.contentHeight, box_size)
        width: parent.width
        cursorShape: Qt.PointingHandCursor
        anchors.verticalCenter: parent.verticalCenter
        onClicked: {
            if(editable){
                root.focus = true
//                checked = !checked
                root.clicked()
            }
        }
    }

}
